/**
 *  This program is free software; you can redistribute it and/or modify it under 
 *  the terms of the GNU General Public License as published by the Free Software 
 *  Foundation; either version 3 of the License, or (at your option) any later 
 *  version.
 *  You should have received a copy of the GNU General Public License along with 
 *  this program; if not, see <http://www.gnu.org/licenses/>. 
 *  Use this application at your own risk.
 *
 *  Copyright (c) 2009 by Harald Mueller and Sofia Lemons.
 */

package android.tether;

import android.R.drawable;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem; //import android.view.MotionEvent;
import android.view.SubMenu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class TetherActivity extends Activity {
	private TetherApplication application = null;
	private ProgressDialog progressDialog;

	private ImageView startBtn = null;
	private OnClickListener startBtnListener = null;
	private ImageView stopBtn = null;
	private OnClickListener stopBtnListener = null;
	private TextView radioModeLabel = null;
	private ImageView radioModeImage = null;
	private RelativeLayout batteryTemperatureLayout = null;

	private TextView batteryTemperature = null;

	private TableRow startTblRow = null;
	private TableRow stopTblRow = null;

	private static int ID_DIALOG_STARTING = 0;
	private static int ID_DIALOG_STOPPING = 1;

	public static final int MESSAGE_CHECK_LOG = 1;
	public static final int MESSAGE_CANT_START_TETHER = 2;
	public static final int MESSAGE_DOWNLOAD_STARTING = 3;
	public static final int MESSAGE_DOWNLOAD_PROGRESS = 4;
	public static final int MESSAGE_DOWNLOAD_COMPLETE = 5;
	public static final int MESSAGE_DOWNLOAD_BLUETOOTH_COMPLETE = 6;
	public static final int MESSAGE_DOWNLOAD_BLUETOOTH_FAILED = 7;
	public static final int MESSAGE_TRAFFIC_START = 8;
	public static final int MESSAGE_TRAFFIC_COUNT = 9;
	public static final int MESSAGE_TRAFFIC_RATE = 10;
	public static final int MESSAGE_TRAFFIC_END = 11;

	public static final String MSG_TAG = "TETHER -> MainActivity";
	public static TetherActivity currentInstance = null;

	private static void setCurrent(TetherActivity current) {
		TetherActivity.currentInstance = current;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.startstoptether);

		// Init Application
		this.application = (TetherApplication) this.getApplication();
		TetherActivity.setCurrent(this);

		// Init Table-Rows
		this.startTblRow = (TableRow) findViewById(R.id.startRow);
		this.stopTblRow = (TableRow) findViewById(R.id.stopRow);
		this.radioModeImage = (ImageView) findViewById(R.id.radioModeImage);
		this.batteryTemperatureLayout = (RelativeLayout) findViewById(R.id.layoutBatteryTemp);
		this.batteryTemperature = (TextView) findViewById(R.id.batteryTempText);

		// Startup-Check
		if (this.application.startupCheckPerformed == false) {
			this.application.startupCheckPerformed = true;

			// Check if required kernel-features are enabled
			if (!this.application.coretask.isNetfilterSupported()) {
				this.openNoNetfilterDialog();
				this.application.accessControlSupported = false;
				this.application.whitelist.remove();
			} else {
				// Check if access-control-feature is supported by kernel
				if (!this.application.coretask.isAccessControlSupported()) {
					if (this.application.settings.getBoolean(
							"warning_noaccesscontrol_displayed", false) == false) {
						this.openNoAccessControlDialog();
						this.application.preferenceEditor.putBoolean(
								"warning_noaccesscontrol_displayed", true);
						this.application.preferenceEditor.commit();
					}
					this.application.accessControlSupported = false;
					this.application.whitelist.remove();
				}
			}

			// Check root-permission, files
			if (!this.application.coretask.hasRootPermission())
				this.openNotRootDialog();

			// Check if binaries need to be updated
			if (this.application.binariesExists() == false
					|| this.application.coretask.filesetOutdated()) {
				if (this.application.coretask.hasRootPermission()) {
					this.application.installFiles();
				}
			}
		}

		// Start Button
		this.startBtn = (ImageView) findViewById(R.id.startTetherBtn);
		this.startBtnListener = new OnClickListener() {
			public void onClick(View v) {
				Log.d(MSG_TAG, "StartBtn pressed ...");
				showDialog(TetherActivity.ID_DIALOG_STARTING);
				new Thread(new Runnable() {
					public void run() {
						boolean started = TetherActivity.this.application
								.startTether();
						TetherActivity.this
								.dismissDialog(TetherActivity.ID_DIALOG_STARTING);
						Message message = Message.obtain();
						if (started != true) {
							message.what = MESSAGE_CANT_START_TETHER;
						} else {
							// Make device discoverable if checked
							if (Integer.parseInt(Build.VERSION.SDK) >= Build.VERSION_CODES.ECLAIR) {
								boolean bluetoothPref = TetherActivity.this.application.settings
										.getBoolean("bluetoothon", false);
								if (bluetoothPref) {
									boolean bluetoothDiscoverable = TetherActivity.this.application.settings
											.getBoolean(
													"bluetoothdiscoverable",
													false);
									if (bluetoothDiscoverable) {
										TetherActivity.this.makeDiscoverable();
									}
								}
							}
							try {
								Thread.sleep(400);
							} catch (InterruptedException e) {
								// Taking a small nap
							}
							String wifiStatus = TetherActivity.this.application.coretask
									.getProp("tether.status");
							if (wifiStatus.equals("running") == false) {
								message.what = MESSAGE_CHECK_LOG;
							}
						}
						TetherActivity.this.viewUpdateHandler
								.sendMessage(message);
					}
				}).start();
			}
		};
		this.startBtn.setOnClickListener(this.startBtnListener);

		// Stop Button
		this.stopBtn = (ImageView) findViewById(R.id.stopTetherBtn);
		this.stopBtnListener = new OnClickListener() {
			public void onClick(View v) {
				Log.d(MSG_TAG, "StopBtn pressed ...");
				// if (TetherActivity.this.lockBtn.isChecked()) {
				// Log.d(MSG_TAG, "Tether was locked ...");
				// TetherActivity.this.application
				// .displayToastMessage(getString(R.string.main_activity_locked));
				// return;
				// }
				showDialog(TetherActivity.ID_DIALOG_STOPPING);
				new Thread(new Runnable() {
					public void run() {
						TetherActivity.this.application.stopTether();
						TetherActivity.this
								.dismissDialog(TetherActivity.ID_DIALOG_STOPPING);
						TetherActivity.this.viewUpdateHandler
								.sendMessage(new Message());
					}
				}).start();
			}
		};
		this.stopBtn.setOnClickListener(this.stopBtnListener);
		// Toggles between start and stop screen
		//TetherActivity.this.application.displayToastMessage("calling toggle");
		this.toggleStartStop();
	}

	@Override
	// public boolean onTrackballEvent(MotionEvent event) {
	// if (event.getAction() == MotionEvent.ACTION_DOWN) {
	// Log.d(MSG_TAG, "Trackball pressed ...");
	// String tetherStatus = this.application.coretask
	// .getProp("tether.status");
	// if (!tetherStatus.equals("running")) {
	// new AlertDialog.Builder(this)
	// .setMessage(
	// getString(R.string.main_activity_trackball_pressed_start))
	// .setPositiveButton(
	// getString(R.string.main_activity_confirm),
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog,
	// int which) {
	// Log
	// .d(MSG_TAG,
	// "Trackball press confirmed ...");
	// TetherActivity.currentInstance.startBtnListener
	// .onClick(TetherActivity.currentInstance.startBtn);
	// }
	// }).setNegativeButton(
	// getString(R.string.main_activity_cancel), null)
	// .show();
	// } else {
	// new AlertDialog.Builder(this)
	// .setMessage(
	// getString(R.string.main_activity_trackball_pressed_stop))
	// .setPositiveButton(
	// getString(R.string.main_activity_confirm),
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog,
	// int which) {
	// Log
	// .d(MSG_TAG,
	// "Trackball press confirmed ...");
	// TetherActivity.currentInstance.stopBtnListener
	// .onClick(TetherActivity.currentInstance.startBtn);
	// }
	// }).setNegativeButton(
	// getString(R.string.main_activity_cancel), null)
	// .show();
	// }
	// }
	// return true;
	// }
	public void onStop() {
		Log.d(MSG_TAG, "Calling onStop()");
		super.onStop();
	}

	public void onDestroy() {
		Log.d(MSG_TAG, "Calling onDestroy()");
		super.onDestroy();
		try {
			unregisterReceiver(this.intentReceiver);
		} catch (Exception ex) {
			;
		}
	}

	public void onResume() {
		Log.d(MSG_TAG, "Calling onResume()");
		this.showRadioMode();
		super.onResume();

		// Check, if the battery-temperatur should be displayed
		if (this.application.settings.getString("batterytemppref", "celsius")
				.equals("disabled") == false) {
			// create the IntentFilter that will be used to listen
			// to battery status broadcasts
			this.intentFilter = new IntentFilter();
			this.intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
			registerReceiver(this.intentReceiver, this.intentFilter);
			this.batteryTemperatureLayout.setVisibility(View.VISIBLE);
		} else {
			try {
				unregisterReceiver(this.intentReceiver);
			} catch (Exception ex) {
				;
			}
			this.batteryTemperatureLayout.setVisibility(View.INVISIBLE);
		}
	}

	private static final int MENU_SETUP = 0;
	private static final int MENU_LOG = 1;
	private static final int MENU_ABOUT = 2;
	private static final int MENU_ACCESS = 3;
	private static final int MENU_TETHER = 4;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		boolean supRetVal = super.onCreateOptionsMenu(menu);
		SubMenu setup = menu.addSubMenu(0, MENU_SETUP, 0,
				getString(R.string.main_activity_settings));
		setup.setIcon(drawable.ic_menu_preferences);
		if (this.application.accessControlSupported) {
			SubMenu accessctr = menu.addSubMenu(0, MENU_ACCESS, 0,
					getString(R.string.main_activity_accesscontrol));
			accessctr.setIcon(drawable.ic_menu_manage);
		}
		SubMenu log = menu.addSubMenu(0, MENU_LOG, 0,
				getString(R.string.main_activity_showlog));
		log.setIcon(drawable.ic_menu_agenda);
		// SubMenu about = menu.addSubMenu(0, MENU_ABOUT, 0,
		// getString(R.string.main_activity_about));
		// about.setIcon(drawable.ic_menu_info_details);
		// SubMenu tether = menu.addSubMenu(0, MENU_TETHER, 0,
		// getString(R.string.main_activity_tether));
		// tether.setIcon(drawable.ic_menu_info_details);
		return supRetVal;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem menuItem) {
		boolean supRetVal = super.onOptionsItemSelected(menuItem);
		Log.d(MSG_TAG, "Menuitem:getId  -  " + menuItem.getItemId());
		try {
			switch (menuItem.getItemId()) {
			case MENU_SETUP:
				startActivityForResult(new Intent(TetherActivity.this,
						SetupActivity.class), 0);
				break;
			case MENU_LOG:
				startActivityForResult(new Intent(TetherActivity.this,
						LogActivity.class), 0);
				break;
			case MENU_ABOUT:
				// startActivityForResult(new Intent(TetherActivity.this,
				// LogActivity.class), 0);
				// this.openAboutDialog();
				break;
			case MENU_ACCESS:
				startActivityForResult(new Intent(TetherActivity.this,
						AccessControlActivity.class), 0);
				break;
			case MENU_TETHER:
				// startActivityForResult(new Intent(TetherActivity.this,
				// TetherActivity.class), 0);
				break;
			}

		} catch (Exception e) {
			TetherActivity.this.application.displayToastMessage(e.toString());
		}

		return supRetVal;
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		if (id == ID_DIALOG_STARTING) {
			progressDialog = new ProgressDialog(this);
			progressDialog.setTitle(getString(R.string.main_activity_start));
			progressDialog
					.setMessage(getString(R.string.main_activity_start_summary));
			progressDialog.setIndeterminate(false);
			progressDialog.setCancelable(true);
			return progressDialog;
		} else if (id == ID_DIALOG_STOPPING) {
			progressDialog = new ProgressDialog(this);
			progressDialog.setTitle(getString(R.string.main_activity_stop));
			progressDialog
					.setMessage(getString(R.string.main_activity_stop_summary));
			progressDialog.setIndeterminate(false);
			progressDialog.setCancelable(true);
			return progressDialog;
		}
		return null;
	}

	/**
	 *Listens for intent broadcasts; Needed for the temperature-display
	 */
	private IntentFilter intentFilter;

	private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			String action = intent.getAction();
			if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
				int temp = (intent.getIntExtra("temperature", 0));
				int celsius = (int) ((temp + 5) / 10);
				int fahrenheit = (int) (((temp / 10) / 0.555) + 32 + 0.5);
				Log.d(MSG_TAG, "Temp ==> " + temp + " -- Celsius ==> "
						+ celsius + " -- Fahrenheit ==> " + fahrenheit);
				if (TetherActivity.this.application.settings.getString(
						"batterytemppref", "celsius").equals("celsius")) {
					batteryTemperature
							.setText(""
									+ celsius
									+ getString(R.string.main_activity_temperatureunit_celsius));
				} else {
					batteryTemperature
							.setText(""
									+ fahrenheit
									+ getString(R.string.main_activity_temperatureunit_fahrenheit));
				}
			}
		}
	};

	public Handler viewUpdateHandler = new Handler() {
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case MESSAGE_CHECK_LOG:
				Log.d(MSG_TAG, "Error detected. Check log.");
				TetherActivity.this.application
						.displayToastMessage(getString(R.string.main_activity_start_errors));
				TetherActivity.this.toggleStartStop();
				break;
			case MESSAGE_CANT_START_TETHER:
				Log.d(MSG_TAG, "Unable to start tethering!");
				TetherActivity.this.application
						.displayToastMessage(getString(R.string.main_activity_start_unable));
				TetherActivity.this.toggleStartStop();
				break;
			case MESSAGE_TRAFFIC_START:
				// TetherActivity.this.trafficRow.setVisibility(View.VISIBLE);
				break;
			case MESSAGE_TRAFFIC_COUNT:
				break;
			case MESSAGE_TRAFFIC_END:
				break;
			case MESSAGE_DOWNLOAD_STARTING:
				break;
			case MESSAGE_DOWNLOAD_PROGRESS:
				break;
			case MESSAGE_DOWNLOAD_COMPLETE:
				break;
			case MESSAGE_DOWNLOAD_BLUETOOTH_COMPLETE:
				Log.d(MSG_TAG, "Finished bluetooth download.");
				TetherActivity.this.startBtn.setClickable(true);
				TetherActivity.this.radioModeLabel.setText("Bluetooth");
				break;
			case MESSAGE_DOWNLOAD_BLUETOOTH_FAILED:
				Log.d(MSG_TAG, "FAILED bluetooth download.");
				TetherActivity.this.startBtn.setClickable(true);
				TetherActivity.this.application.preferenceEditor.putBoolean(
						"bluetoothon", false);
				TetherActivity.this.application.preferenceEditor.commit();
				// TODO: More detailed popup info.
				TetherActivity.this.application
						.displayToastMessage("No bluetooth module for your kernel! Please report your kernel version.");
			default:
				TetherActivity.this.toggleStartStop();
			}
			super.handleMessage(msg);
		}
	};

	private void makeDiscoverable() {
		Log.d(MSG_TAG, "Making device discoverable ...");
		Intent discoverableIntent = new Intent(
				BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
		discoverableIntent.putExtra(
				BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
		startActivity(discoverableIntent);
	}

	private void toggleStartStop() {
		boolean dnsmasqRunning = false;
		boolean pandRunning = false;
		try {
			dnsmasqRunning = this.application.coretask
					.isProcessRunning("bin/dnsmasq");
		} catch (Exception e) {
			TetherActivity.this.application
					.displayToastMessage("Unable to check if dnsmasq is currently running!");
		}
		try {
			pandRunning = this.application.coretask
					.isProcessRunning("bin/pand");
		} catch (Exception e) {
			TetherActivity.this.application
					.displayToastMessage("Unable to check if pand is currently running!");
		}
		boolean natEnabled = this.application.coretask.isNatEnabled();
		boolean usingBluetooth = this.application.settings.getBoolean(
				"bluetoothon", false);
		if ((dnsmasqRunning == true && natEnabled == true)
				|| (usingBluetooth == true && pandRunning == true)) {
			this.startTblRow.setVisibility(View.GONE);
			this.stopTblRow.setVisibility(View.VISIBLE);
			// Animation
			// if (this.animation != null)
			// this.stopBtn.startAnimation(this.animation);

			// Checking, if "wired tether" is currently running
			String tetherMode = this.application.coretask
					.getProp("tether.mode");
			String tetherStatus = this.application.coretask
					.getProp("tether.status");
			if (tetherStatus.equals("running")) {
				if (!(tetherMode.equals("wifi") == true || tetherMode
						.equals("bt") == true)) {
					TetherActivity.this.application
							.displayToastMessage(getString(R.string.main_activity_start_wiredtethering_running));
				}
			}

			// Checking, if cyanogens usb-tether is currently running
			tetherStatus = this.application.coretask
					.getProp("tethering.enabled");
			if (tetherStatus.equals("1")) {
				TetherActivity.this.application
						.displayToastMessage(getString(R.string.main_activity_start_usbtethering_running));
			}

			// this.application.trafficCounterEnable(true);
			this.application.clientConnectEnable(true);
			this.application.dnsUpdateEnable(true);

			this.application.showStartNotification();

			// Check, if the lockbutton should be displayed
			// if (TetherActivity.this.application.settings.getBoolean(
			// "lockscreenpref", true) == false) {
			// TetherActivity.this.lockButtonCheckbox
			// .setVisibility(View.VISIBLE);
			// }
		} else if (dnsmasqRunning == false && natEnabled == false) {
			this.startTblRow.setVisibility(View.VISIBLE);
			this.stopTblRow.setVisibility(View.GONE);
			// this.application.trafficCounterEnable(false);
			// Animation
			// if (this.animation != null)
			// this.startBtn.startAnimation(this.animation);
			// Notification
			this.application.notificationManager.cancelAll();

			// Check, if the lockbutton should be displayed
			// TetherActivity.this.lockButtonCheckbox.setVisibility(View.GONE);
		} else {
			this.startTblRow.setVisibility(View.VISIBLE);
			this.stopTblRow.setVisibility(View.VISIBLE);
			TetherActivity.this.application
					.displayToastMessage(getString(R.string.main_activity_start_unknownstate));
		}
		this.showRadioMode();
		System.gc();
	}

	// private String formatCount(long count, boolean rate) {
	// // Converts the supplied argument into a string.
	// // 'rate' indicates whether is a total bytes, or bits per sec.
	// // Under 2Mb, returns "xxx.xKb"
	// // Over 2Mb, returns "xxx.xxMb"
	// if (count < 1e6 * 2)
	// return ((float) ((int) (count * 10 / 1024)) / 10 + (rate ? "kbps"
	// : "kB"));
	// return ((float) ((int) (count * 100 / 1024 / 1024)) / 100 + (rate ?
	// "mbps"
	// : "MB"));
	// }

	private void openNoNetfilterDialog() {
		LayoutInflater li = LayoutInflater.from(this);
		View view = li.inflate(R.layout.nonetfilterview, null);
		new AlertDialog.Builder(TetherActivity.this).setTitle(
				getString(R.string.main_activity_nonetfilter)).setView(view)
				.setNegativeButton(getString(R.string.main_activity_exit),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								Log.d(MSG_TAG, "Close pressed");
								TetherActivity.this.finish();
							}
						}).setNeutralButton(
						getString(R.string.main_activity_ignore),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								Log.d(MSG_TAG, "Override pressed");
								TetherActivity.this.application
										.displayToastMessage("Ignoring, note that this application will NOT work correctly.");
							}
						}).show();
	}

	private void openNoAccessControlDialog() {
		LayoutInflater li = LayoutInflater.from(this);
		View view = li.inflate(R.layout.noaccesscontrolview, null);
		new AlertDialog.Builder(TetherActivity.this).setTitle(
				getString(R.string.main_activity_noaccesscontrol))
				.setView(view).setNeutralButton(
						getString(R.string.main_activity_ok),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								Log.d(MSG_TAG, "OK pressed");
								TetherActivity.this.application
										.displayToastMessage(getString(R.string.main_activity_accesscontrol_disabled));
							}
						}).show();
	}

	private void openNotRootDialog() {
		LayoutInflater li = LayoutInflater.from(this);
		View view = li.inflate(R.layout.norootview, null);
		new AlertDialog.Builder(TetherActivity.this).setTitle(
				getString(R.string.main_activity_notroot)).setView(view)
				.setNegativeButton(getString(R.string.main_activity_exit),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								Log.d(MSG_TAG, "Exit pressed");
								TetherActivity.this.finish();
							}
						}).setNeutralButton(
						getString(R.string.main_activity_ignore),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								Log.d(MSG_TAG, "Ignore pressed");
								TetherActivity.this.application.installFiles();
								TetherActivity.this.application
										.displayToastMessage("Ignoring, note that this application will NOT work correctly.");
							}
						}).show();
	}

	private void showRadioMode() {
		boolean usingBluetooth = this.application.settings.getBoolean(
				"bluetoothon", false);
		if (usingBluetooth) {
			this.radioModeImage.setImageResource(R.drawable.bluetooth);
		} else {
			this.radioModeImage.setImageResource(R.drawable.wifi);
		}
	}

	// public void openUpdateDialog(final String downloadFileUrl,
	// final String fileName, final String message,
	// final String updateTitle) {
	// LayoutInflater li = LayoutInflater.from(this);
	// Builder dialog;
	// View view;
	// view = li.inflate(R.layout.updateview, null);
	// TextView messageView = (TextView) view.findViewById(R.id.updateMessage);
	// TextView updateNowText = (TextView) view
	// .findViewById(R.id.updateNowText);
	// if (fileName.length() == 0) // No filename, hide 'download now?' string
	// updateNowText.setVisibility(View.GONE);
	// messageView.setText(message);
	// dialog = new AlertDialog.Builder(TetherActivity.this).setTitle(
	// updateTitle).setView(view);
	//
	// if (fileName.length() > 0) {
	// // Display Yes/No for if a filename is available.
	// dialog.setNeutralButton(getString(R.string.main_activity_no),
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog,
	// int whichButton) {
	// Log.d(MSG_TAG, "No pressed");
	// }
	// });
	// // dialog.setNegativeButton(getString(R.string.main_activity_yes),
	// // new DialogInterface.OnClickListener() {
	// // // public void onClick(DialogInterface dialog, int whichButton) {
	// // // Log.d(MSG_TAG, "Yes pressed");
	// // //
	// // TetherActivity.this.application.downloadUpdate(downloadFileUrl,
	// // fileName);
	// // // }
	// // });
	// } else
	// dialog.setNeutralButton(getString(R.string.main_activity_ok),
	// new DialogInterface.OnClickListener() {
	// public void onClick(DialogInterface dialog,
	// int whichButton) {
	// Log.d(MSG_TAG, "Ok pressed");
	// }
	// });
	//
	// dialog.show();
	// }

}
